﻿using System;

namespace DimensionsHelper.Common.Metadata.Axis;

/// <summary>
///     轴元素的计算区间
/// </summary>
public enum AxisElementCalculationScope
{
    /// <summary>
    ///     计算所有轴元素
    /// </summary>
    AllElements,

    /// <summary>
    ///     计算此元素之前的轴元素
    /// </summary>
    PrecedingElements
}


/// <summary>
///     轴表达式元素的后缀设定类型
/// </summary>
public enum AxisElementSuffixType
{
    // CalculationScope=AllElements|PrecedingElements
    CalculationScope,

    // CountsOnly=True|False
    CountsOnly,

    // Decimals=DecimalPlaces
    Decimals,

    // Factor=FactorValue
    Factor,

    // IsFixed=True|False 
    IsFixed,

    // IsHidden=True|False   
    IsHidden,

    // IsHiddenWhenColumn=True|False
    IsHiddenWhenColumn,

    // IsHiddenWhenRow=True|False 
    IsHiddenWhenRow,

    // IncludeInBase=True|False
    IncludeInBase,

    // IsUnweighted=True|False
    IsUnweighted,

    // Multiplier=MultiplierVariable
    Multiplier,

    // Weight=WeightVariable
    Weight
}


/// <summary>
///     轴元素后缀
/// </summary>
public class AxisElementSuffix : ICloneable
{
    public AxisElementSuffix(AxisElementSuffixType type)
    {
        Type = type;
    }


    /// <summary>
    ///     后缀类型
    /// </summary>
    public AxisElementSuffixType Type { get; }


    /// <summary>
    ///     后缀值
    /// </summary>
    public object Value { get; set; } = string.Empty;

    public object Clone()
    {
        return new AxisElementSuffix(Type) { Value = Value };
    }

    public bool Equals(AxisElementSuffix other)
    {
        return other != null && other.Type == Type && other.Value == Value;
    }

    public override string ToString()
    {
        switch (Type)
        {
            case AxisElementSuffixType.CalculationScope:
                return $"{nameof(AxisElementSuffixType.CalculationScope)}={Value}";
            case AxisElementSuffixType.CountsOnly:
                return $"{nameof(AxisElementSuffixType.CountsOnly)}={Value}";
            case AxisElementSuffixType.Decimals:
                return $"{nameof(AxisElementSuffixType.Decimals)}={Value}";
            case AxisElementSuffixType.Factor:
                return $"{nameof(AxisElementSuffixType.Factor)}={Value}";
            case AxisElementSuffixType.IsFixed:
                return $"{nameof(AxisElementSuffixType.IsFixed)}={Value}";
            case AxisElementSuffixType.IsHidden:
                return $"{nameof(AxisElementSuffixType.IsHidden)}={Value}";
            case AxisElementSuffixType.IsHiddenWhenRow:
            case AxisElementSuffixType.IsHiddenWhenColumn:
                return $"{nameof(AxisElementSuffixType.IsHiddenWhenColumn)}={Value}";
            case AxisElementSuffixType.IncludeInBase:
                return $"{nameof(AxisElementSuffixType.IncludeInBase)}={Value}";
            case AxisElementSuffixType.IsUnweighted:
                return $"{nameof(AxisElementSuffixType.IsUnweighted)}={Value}";
            case AxisElementSuffixType.Multiplier:
                return $"{nameof(AxisElementSuffixType.Multiplier)}={Value}";
            case AxisElementSuffixType.Weight:
                return $"{nameof(AxisElementSuffixType.Weight)}={Value}";
            default:
                return string.Empty;
        }
    }
}